$(function() {
    $('.menuIcon').on('click', function() {
        var navsub = $('.navbar-nav');
        if (navsub.hasClass('open')) {
            navsub.show();
            navsub.removeClass('open');
            navsub.slideUp(300).addClass('animated');
            $(this).removeClass('menu-unfold');
            $('.mobileShadow').hide();
            $('body').css('overflow','visible');
        } else {
            navsub.addClass('open');
            navsub.slideDown(300).addClass('animated');
            $(this).addClass('menu-unfold');
            $('.mobileShadow').show();
            $('body').css('overflow','hidden');
        }
    });

    //遮罩
    $('.mobileShadow').height($("body").height());
    $('.mobileShadow').on('click', function() {
        $('.navbar-nav').slideUp();
        $('.navbar-nav').removeClass('open');
        $('.menuIcon').removeClass('menu-unfold');
        $('.mobileShadow').hide(); //移除遮罩层
        $('body').css('overflow','visible');
    });

    //向上滑动关闭导航
    var StartY,EndY;
    //触屏开始
    $(document).on('touchstart', function (e) {
        StartY  = e.originalEvent.targetTouches[0].pageY;
    });
    //触屏结束
    $(document).on('touchend', function (e) {
      EndY  = e.originalEvent.changedTouches[0].pageY;
      if(parseFloat(StartY)-parseFloat(EndY)>5){
        $('.navbar-nav').slideUp();
        $('.navbar-nav').removeClass('open');
        $('.menuIcon').removeClass('menu-unfold');
        $('.mobileShadow').hide(); //移除遮罩层
        $('body').css('overflow','visible');
      }
    });


});